require("util.js");

var e = require("wxApi.js"), n = require("wxRequest.js"), o = require("api.js"), t = getApp();

module.exports = {
    getUsreInfo: function(n) {
        var o = this, r = "";
        e.wxLogin()().then(function(o) {
            return r = o.code, null == n ? e.wxGetUserInfo()() : n;
        }).then(function(e) {
            console.log(e.userInfo), console.log("成功获取用户信息(公开信息)"), t.globalData.userInfo = e.userInfo, 
            t.globalData.isGetUserInfo = !0;
            var n = {
                js_code: r,
                encryptedData: e.encryptedData,
                iv: e.iv,
                avatarUrl: e.userInfo.avatarUrl,
                nickname: e.userInfo.nickName
            };
            o.getOpenId(n);
        }).catch(function(e) {
            console.log("error: " + e.errMsg);
        });
    },
    getOpenId: function(e) {
        var r = o.getOpenidUrl();
        n.postRequest(r, e).then(function(e) {
            "200" == e.data.status ? (console.log("openid 获取成功"), t.globalData.openid = e.data.openid, 
            t.globalData.isGetOpenid = !0) : console.log(e);
        });
    }
};